﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Networking
{
    /// <summary>
    /// Packet of type PacketClientInit, the client can ask the server to disconnect all the others client to serve him
    /// </summary>
    public class ClientInitPacket : Packet
    {

        /// <summary>
        /// If the server can be shared
        /// </summary>
        public bool IsShared { get; private set; }

        /// <summary>
        /// Creates a new instance of PacketClientInit with the provided share setting
        /// </summary>
        /// <param name="AcceptedSecurity"></param>
        public ClientInitPacket(bool IsShared)
            : base(PacketType.ClientInit)
        {
            this.IsShared = IsShared;
        }

        /// <summary>
        /// Creates a new instance of ClientInitPacket extracting all the parameters from the byte buffer
        /// </summary>
        /// <param name="buffer">The byte buffer containing the packet data</param>
        public ClientInitPacket(byte[] buffer)
            : base(PacketType.ClientInit, buffer)
        {
            //
        }

        /// <summary>
        /// Serializes the packet in order to send it
        /// </summary>
        /// <returns>The bytes of the packet</returns>
        public override byte[] Serialize()
        {
            //return new byte[0] { (byte)(IsShared ? 0x1 : 0x0) };
            return new byte[] { (byte)(IsShared ? 0x1 : 0x0) };
   
        }

        public override void Load(byte[] buffer)
        {
            if (buffer.Length != 1) throw new BufferSizeMismatchException(1);

            IsShared = (buffer[0] == 0x1) ? true : false;
            
        }
    }
}
